package hit.core;
import hit.reports.Visitor;
/**
 * A user defined method of grouping products and items together within a StorageUnit.
 *
 */
public class ProductGroup extends ProductContainer
{
	/**
	 * The link to the Parent Container
	 */
	private ProductContainer parentContainer;
	
	/**
	 * The size of the three month supply.
	 */
	private Size threeMonth;
	
	private int parentID;

	/**
	 * Creates a new instance of the ProductGroup class.
	 * @param name The name of the ProductGroup
	 */
	public ProductGroup(String name)
	{
		super(name);
		threeMonth = new Size();
		parentContainer = null;
	}

	@Override
	public ProductContainer GetParentContainer() {
		return parentContainer;
	}

	public void SetParentContainer(ProductContainer parentContainer)
			throws IllegalArgumentException{
		
		if (parentContainer == null)
			throw new IllegalArgumentException();
		this.parentContainer = parentContainer;
	}

	public int GetParentID() {
		if (parentContainer != null) {
			return parentContainer.getId();
		}
		return parentID;
	}
	
	public void SetParentID(int parentID) {
		this.parentID = parentID;
	}

	public Size GetThreeMonth() {
		return threeMonth;
	}

	public void SetThreeMonth(Size threeMonth) throws IllegalArgumentException{
		if (!Size.IsValid(threeMonth)){
			throw new IllegalArgumentException();
		}
		this.threeMonth = threeMonth;
	}

	/**
	 * Checks to see if a given ProductGroup is valid.
	 * @param productGroup The ProductGroup to check.
	 * @return True if valid, false otherwise.
	 */
	@Override
	public boolean IsValid()
	{
		return Size.IsValid(threeMonth) && parentContainer != null && !name.isEmpty();
	}

	@Override
	public void Accept(Visitor visitor){
		visitor.VisitProductGroup(this);
		for (ProductGroup gp : productGroups){
			gp.Accept(visitor);
		}
	}
	
	@Override
	public void AcceptPost(Visitor visitor){
		for (ProductGroup gp : productGroups){
			gp.AcceptPost(visitor);
		}
		visitor.VisitProductGroupPost(this);
	}
	/*
	@Override
	public int compareTo(Object o) {
		ProductGroup o_pg = (ProductGroup)o;
		return name.compareTo(o_pg.GetName());
	} //*/
}
